#[derive(FromForm)]
struct WsClipList {
    skip_number: usize
}

#[derive(Serialize)]
struct WsClipReturn {
    id: usize,
    title: String,
    dub_file: String,
    bt_file: String
}

#[post("/ws_lib/clip_list", data="<form>")]
fn ws_clip_list(form: Form<WsClipList>, state: State<MySqlDriver>) -> Json<Value> {
    let mut clip_list: Vec<WsClipReturn> = Vec::new();
    let pool_result: Result<Pool, mysql::Error> = Pool::new(state.driver.as_str());
    let pool: Pool;
    if let Ok(p) = pool_result {
        pool = p;
    } else {
        return Json(to_value(clip_list).unwrap());
    }
    let conn_result: Result<PooledConn, mysql::Error> = pool.get_conn();
    let mut conn: PooledConn;
    if let Ok(c) = conn_result {
        conn = c;
    } else {
        return Json(to_value(clip_list).unwrap());
    }

    let sql: String = format!("SELECT `clip_o`.`id`, `copy_o`.`title`, `clip_o`.`dub_file`, `t`.`bt_file` FROM `clip_order` AS `clip_o` INNER JOIN `topic` AS `t` ON `t`.`id` = `clip_o`.`topic_id` INNER JOIN `copywrite_order` AS `copy_o` ON `copy_o`.`id` = `clip_o`.`copywrite_id` WHERE `clip_o`.`status` = 0 ORDER BY `clip_o`.`id` ASC LIMIT {}, 10", form.skip_number);
    let rows: Vec<Row> = conn.query(sql).unwrap();
    for row in rows {
		let (id, title, dub_file, bt_file): (usize, String, String, String) = from_row(row);
        let bt_file_hostr: HoString = HoString::copy_string(bt_file);
        let bt_file_array: Vec<HoString> = bt_file_hostr.split_str("|");
        let mut bt_file_first: String = String::new();
        if let Some(first) = bt_file_array.get(0) {
            bt_file_first = first.to_string();
        }

		clip_list.push(WsClipReturn {
			id: id,
			title: title,
            dub_file: dub_file,
            bt_file: bt_file_first
        });
    }
    return Json(to_value(clip_list).unwrap());
}

